<?php

namespace App\Http\Controllers;

use App\Listeners\EntrustListener;
use App\Library\ETH\EthereumFunction;
use LaraBlockIo;
use App\Library\BTC\BitcoinFunction;
use Illuminate\Http\Request;
use App\Models\Message;
use App\Models\Property;
use App\Models\Recharge;
use App\DesignPatterns\Observer\EntrustCollection;

class TestController extends Controller
{
    /**
     * [index description]
     * @access 
     * @param  Request $request [description]
     * @return [type]           [description]
     */
    public function index(Request $request)
    {
        

        $collection = new EntrustCollection(1);
        dd($collection);
        $collection->entry();

        die();
        $order = Recharge::find(1);

        dd($order->appeal_order);


        $account = "baidu.com";
        $email = "123456@qq.com";
        $phone = "15999888888";

        dump(hideStar($email));
        dump(hideStar($phone));
        dd(hideStar($account));

        dd(collect($arr)->count());

        $string = '1,4,5';
        $orderby = 'field(cid,'.$string.')';

        $data = Property::where('uid', 31)->whereIn('cid', [1, 4, 5])->orderByRaw($orderby)->get()->toArray();

        dd($data);

        $list = (new Message())->syspublishsmsAll(['msg_id' => 24, 'uid' => 1, 'message' => ['左老板'], 'push_message' => ['推送消息']]);

        dd($list);

        //dd(get_microtimes());
        //event(new EntrustListener());

        //$block = new BitcoinFunction('btc');
        //dd($block);

        //return view('test');

        //dd(memory_get_usage());
        //$block = new BitcoinFunction('btc');

        //dump($block->makeTransaction('1', '3HM2Db5XjevhDBsHuFKbo8ypyq1AP7LscG', '32SWjhYc8RpMje4nMc4E2eJGtTuGgyP9ro'));

        //dump($block->getWalletBalance());

        /*$web3 = new EthereumFunction();

        $accounts = $web3->getAllAccount();

        $wei = $web3->toWei('10');
        $hex = $web3->toHex($wei);
        dump($wei, $hex);

        $res = $web3->makeTransaction($accounts[0], $accounts[1], $hex);
        dump($res);*/

        //dump($web3->toEther($value, 'ether'));

        //dump($block->getAllAddress());

        //dump($block->createWalletAddress());

        //返回一个blockio对象
        //dump(LaraBlockIo::getBlockIo());
        //获取账号余额
        //dump(LaraBlockIo::getBalanceInfo());
        //获取与API键相关联的网络
        //dump(LaraBlockIo::getNetwork());
        //获取与所选网络中所有地址相关联的余额
        //dump(LaraBlockIo::getAvailableBalance());
        //获取在选定网络中等待确认的余额
        //dump(LaraBlockIo::getPendingReceivedBalance());
        //通过指定地址（ES）获得地址（ES）平衡
        //dump(LaraBlockIo::getAddressesBalanceByAddress($addresses));
        //按指定的标签获取地址（ES）余额
        //dump(LaraBlockIo::getAddressesBalanceByLabels($labels));
        //获取用户余额
        //LaraBlockIo::getUsersBalance($userIds);
        //收取交易费用（提取、发送）
        //LaraBlockIo::getNetworkFeeEstimate($amounts, $addresses);

        // 创建新地址.
        //LaraBlockIo::createAddress($label);
        //获取所有的地址信息
        //dump(LaraBlockIo::getAddressesInfo());
        //获取地址信息不包含余额
        //dump(LaraBlockIo::getAddressesInfoWithoutBalances());
        //获取所有的地址
        //dump(LaraBlockIo::getAddresses());
        //
        //dump(LaraBlockIo::getAddressesWithoutBalances());
        //根据label获取地址
        //$label = 'default';
        //dump(LaraBlockIo::getAddressByLabel($label));

        //dump(LaraBlockIo::getUsers());
        //$userId = 0;
        //dump(LaraBlockIo::getUserAddress($userId));
    }

    public function sendSocket()
    {
        $type = 'publish';
        //$content = '{"type":1,"content":"3333"}';
        $content = [
            'type' => 1,
            'content' => '我爱北京天安门',
        ];
        $content = json_encode($content);
        $uid = 123;
        $push_api_url = 'http://114.215.40.82:2121/';
        //$push_api_url = "http://sj1.51tuanli.com/";
        $post_data = [
            'type' => $type,
            'content' => $content,
            'to' => $uid,
        ];

        $post_params = http_build_query($post_data);

        //$push_api_url = "http://114.215.40.82:2121/?".$post_params;

        dump($push_api_url);

        $ch = curl_init();

        curl_setopt($ch, CURLOPT_URL, $push_api_url);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_HEADER, 0);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
        curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:'));
        //dd($ch);
        $return = curl_exec($ch);
        curl_close($ch);
        dump($return);
    }
}
